const state = {
  courseList: [],
  coursePage: {},
  typeList: [],
  typePage: {},
  orgList: [],
  orgPage: {}
}

const actions = {
  saveList: ({ commit }, payload) => {
    commit('SAVELIST', payload)
  },
  saveTypeList: ({ commit }, payload) => {
    commit('SAVETYPELIST', payload)
  },
  saveOrg: ({ commit }, payload) => {
    commit('SAVEORG', payload)
  }
}

const mutations = {
  SAVELIST: (state, payload) => {
    if (payload.result.length === 0) {
      state.courseList = []
    } else {
      state.courseList = payload.result.map(item => {
        return {
          id: item.id,
          name: item.name,
          publicAt: item.public_at || '',
          belongArea: item.belong_area || '',
          publicOrg: item.public_org || '',
          corpType: item.corp_type || '',
          contactName: item.contact_name || '',
          course_type_id: item.course_type_id || '',
          content: item.content || ''
        }
      })
    }
    state.coursePage = {
      size: 10,
      total: payload.resultNum,
      number: payload.number || 1
    }
  },
  SAVETYPELIST: (state, payload) => {
    state.typeList = payload.result,
    state.typePage = {
      size: 10,
      total: payload.resultNum,
      number: payload.number || 1
    }
  },
  SAVEORG: (state, payload) => {
    state.orgList = payload.result.map(item => {
        return {
            ...item,
            allianceId: item.alliance_id
        }
    })
    state.orgPage = {
        size: 10,
        total: payload.resultNum,
        number: payload.number
    }
  }
}


export default {
  state,
  actions,
  mutations
}